package com.villaday.idf.adapter3;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model3.HotelsEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 民宿
 */

public class FindJiuDianAdapter<T> extends AbsRecyclerViewAdapter<HotelsEntity.BodyEntity.ListEntityX> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private  String roleType;


    public FindJiuDianAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_bourn_detical_jiudian, R.layout.item_page_loading,
                R.layout.item_page_bottom, R.layout.item_recycler, R.layout.item_bourn_detical_jiudian_0);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }
    public void setRoleType(){
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();
    }
    @Override
    public int getItemType(HotelsEntity.BodyEntity.ListEntityX d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HotelsEntity.BodyEntity.ListEntityX d, int position) {


        switch (d.getMyType()) {
            case 3:
               /* RecyclerView rv = (RecyclerView) holder.getView(R.id.rv_inner);
                rv.setLayoutManager(new GridLayoutManager(context, 3));
                MinSuInnerAdapter minSuInnerAdapter = new MinSuInnerAdapter(context,position,onClickListener);
                rv.setAdapter(minSuInnerAdapter);
                minSuInnerAdapter.setData(d.getBusinessDistricts());*/
                break;
            case 0:
            case 4:
holder.setViewVisible(R.id.tv_zhuanNum,"0".equals(roleType)?View.INVISIBLE : "0".equals(d.getAddBrokerageAmountValue())?View.INVISIBLE:View.VISIBLE);
                holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL() + "")
                        .bindTextViewWithHtml(R.id.tv_priceFuHao, "&yen;")
                        .bindTextView(R.id.tv_title, d.getName())

                        .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ?View.GONE : "0".equals(d.getBrokerAgeAmountValue())?View.GONE:View.VISIBLE)

                        .setViewVisible(R.id.tv_Zhuan, "0".equals(roleType)  ?View.GONE : "0".equals(d.getBrokerAgeAmountValue())?View.GONE:View.VISIBLE)
                        .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)
                        .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                        .bindTextViewWithHtml(R.id.tv_Zhuan, "立返" + "&yen;" + d.getBrokerAgeAmountValue() + "起")
                        .bindTextViewWithHtml(R.id.tv_zhuanNum, "加返" + "&yen;" + d.getAddBrokerageAmountValue()+ "起")


                        .bindTextViewWithHtml(R.id.tv_price, d.getCurrentPriceValue());
                if (d.getAround()==null){
                    holder.bindTextView(R.id.tv_des, d.getLevelName() + (TextUtils.isEmpty(d.getArea())?"":" | " +d.getArea()) );

                }else {
                    holder.bindTextViewWithHtml(R.id.tv_des, d.getLevelName() + (TextUtils.isEmpty(d.getArea())?"":" | " +d.getArea()) +(" | "+"距"+d.getAround().getAroundName()+ String.format(context.getResources().getString(R.string.jdtext),d.getAround().getAroundDist()+"")+"公里"));

                }

                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi), false);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_priceFuHao), true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), false);


                List<String> tags = new ArrayList<>();
                tags.addAll(d.getTags());
                TagFlowLayout tfl = (TagFlowLayout) holder.getView(R.id.fl_history);
                if ((d.getTags() != null && d.getTags().size() != 0)) {
                    TagAdapter<T> tagAdapter = new TagAdapter<T>((List<T>) tags) {
                        @Override
                        public View getView(FlowLayout parent, int position, T s) {

                            LayoutInflater inflater = LayoutInflater.from(context);
                            TextView tv;
                            tv = (TextView) inflater.inflate(R.layout.tv_home_tag, null);
                            if (s instanceof String) {
                                //当地热门

                                String hot = (String) s;
                                if (hot.length() > 10) {
                                    tv.setText(hot.substring(0, 6) + "...");

                                } else {
                                    tv.setText(hot);

                                }

                            }


                            return tv;
                        }
                    };
                    tfl.setAdapter(tagAdapter);


                }

                break;
            case 1:
                onAdapterCallbackListener.onCallback();
                break;
        }


    }
}
